package part19;

import java.util.EnumMap;
import java.util.Map;

/**
 * @author wcj
 * @Date 2021/6/5 19:57
 * @Version 1.0
 */
public class Part199 {

    /**
     * EnumMap：键必须为Enum的实例值。为一种专门为枚举设计的map
     *
     * @param args
     */
    public static void main(String[] args) {
        EnumMap<AlarmPoints, Command> em = new EnumMap<>(AlarmPoints.class);
        em.put(AlarmPoints.KITCHEN, new Command() {
            @Override
            public void action() {
                System.out.println("Kitchen fire!");
            }
        });
        em.put(AlarmPoints.BATHROOM, new Command() {
            @Override
            public void action() {
                System.out.println("Bathroom alert!");
            }
        });
        for (Map.Entry<AlarmPoints, Command> e : em.entrySet()) {
            System.out.println(e.getKey() + " ");
            e.getValue().action();
        }
        try {
            em.get(AlarmPoints.UTILITY).action();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

interface Command {

    /**
     * action
     */
    void action();
}
